package
{
	public class Block
	{
		//El X e Y interno
		private var _x:int;
		private var _y:int;
		//El tipo de bloque del que forma parte
		private var _type:String;
		//La representacion del bloque
		private var _display:Box;
		
		public function Block(x:int, y:int, type:String)
		{
			this._x = x;
			this._y = y;
			this._type = type;
		}
		/* Getters y Setters */
		public function set x(value:int):void
		{
			this._x = value;
			//Si tiene display, tambien asigno su X
			if(this._display)
				this._display.x = this._x * Box.SIZE;
		}
		
		public function set y(value:int):void
		{
			this._y = value;
			//Si tiene display, tambien asigno su Y
			if(this._display)
				this._display.y = this._y * Box.SIZE;
		}
		
		public function set type(value:String):void
		{
			this._type = value;
		}
		
		public function get x():int
		{
			return this._x;
		}		
		
		public function get y():int
		{
			return this._y;
		}
		/**
		 * Genera una caja si no existe y la devuelve para mostrarla en pantalla.
		 * Si el display es null, genera uno nuevo
		 */
		public function toDisplay():Box
		{
			var color:uint;
			switch(this._type)
			{
				case Forma.I:
					color = 0xFF0000;
					break;
				case Forma.J:
					color = 0x800080;
					break;
				case Forma.L:
					color = 0xFF00FF;
					break;
				case Forma.O:
					color = 0xFF8040;
					break;
				case Forma.S:
					color = 0xFFFF00;
					break;
				case Forma.T:
					color = 0x0000FF;
					break;
				case Forma.Z:
					color = 0x00FF00;
					break;				
			}
			
			this._display = this._display ? this._display : new Box(color);
			this._display.x = this._x * Box.SIZE;
			this._display.y = this._y * Box.SIZE;
			return this._display;
		}
	}
}